﻿using Exceptionless;
using SalesPages.WebApi.App_Start;
using System.Web;
using System.Web.Http.Filters;
using System.Web.Mvc;

namespace SalesPages.WebApi
{
    public class FilterConfig
    {
        public static void RegisterGlobalFilters(GlobalFilterCollection filters)
        {
            filters.Add(new HandleErrorAttribute());
            
        }
    }

    public class SalesPagesHandleErrorAttribute : ExceptionFilterAttribute
    {
        public override void OnException(HttpActionExecutedContext actionExecutedContext)
        {
            if (actionExecutedContext.Response.StatusCode ==  System.Net.HttpStatusCode.NotFound)
                ExceptionlessClient.Default.SubmitNotFound(actionExecutedContext.ActionContext.Request.RequestUri.AbsolutePath);
            else
                ExceptionlessClient.Default.SubmitException(actionExecutedContext.Exception);

            base.OnException(actionExecutedContext);
        }
    }
}


    

